package com.pigotech.ptwo.UI.Activity;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.pigotech.ptwo.adapter.NormalVideoAdapter;
import com.pigotech.ptwo.R;
import com.pigotech.ptwo.entity.NormalVideo;
import com.pigotech.ptwo.interfaces.CallBack;
import com.pigotech.ptwo.socket.CommandSocket;
import com.pigotech.ptwo.widget.HorizontalListView;

import java.util.List;

public class NormalVideoListActivity extends Activity implements CallBack{

    private HorizontalListView lv_normal_video = null;
    private List<NormalVideo> dataList = null;
    private NormalVideoAdapter normalVideoAdapter = null;
    private TextView tv_video_name;
    private ImageView iv_video;
    private ListView listview;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_normal_video_list);
        initView ();
        initData();

    }

    private void initView () {
        tv_video_name = (TextView) findViewById(R.id.tv_video_name);
        iv_video = (ImageView) findViewById(R.id.iv_video);
        lv_normal_video = (HorizontalListView) findViewById(R.id.lv_normal_video);
        lv_normal_video.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                tv_video_name.setText(dataList.get(position).getFilename());
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
//        listview.setOnScrollListener();
//        lv_normal_video.setOnScrollListener(new AbsListView.OnScrollListener() {
//            @Override
//            public void onScrollStateChanged(AbsListView view, int scrollState) {
//
//            }
//
//            @Override
//            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
//                Log.d("Scroll", "*****" + firstVisibleItem);
//            }
//        });

    }

    private void initData() {
        CommandSocket.getInstance().getNormalVideo();
        CommandSocket.getInstance().setCallBack(this);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                CommandSocket.getInstance().doCallBackMethod();
            }
        }, 1000);

    }

    @Override
    public void doSomething(List<NormalVideo> list) {
        dataList = list;
        normalVideoAdapter = new NormalVideoAdapter(dataList, NormalVideoListActivity.this);
        lv_normal_video.setAdapter(normalVideoAdapter);
    }

}
